package ControllerLayer;

import ModelLayer.*;

import java.util.ArrayList;


/**
 * This is a controller class for the tool CRUD use case.
 * 
 * @author Group 4, dm82
 * @version 07-12-12
 */
public class ToolCtr
{
    private ToolContainer   toolContainer;
    private static ToolCtr  instance;
    private static long idCount;
    /**
     * Constructor for objects of class ToolCtr
     */
    private ToolCtr()
    {
        idCount =0;
        toolContainer = ToolContainer.getInstance();
    }
    
    /**
     * This method returns an instance of this class, in accordance with singleton implementation.
     */
    public static ToolCtr getInstance()
    {
        if(instance == (null))
        {
            instance = new ToolCtr();
        }
        return instance;
    }
    
    /**
     * This method creates a new tool description.
     * 
     * @param   description A description of the tools.
     */
    public void createToolDescription(String description, double price)
    {
        idCount++;
        toolContainer.addToolDescription(new ToolDescription(idCount,description, price));
    }
    
    /**
     * This method updates the attributes of a tool description.
     * 
     * @param   id          The id of the tool description.
     * @param   description The new description.
     * @param   price       The new price.
     */
    public void editToolDescription(long id, String description, double price)
    {
        toolContainer.editToolDescription(id,description,price);
    }
    
    /**
     * This method returns a tool description.
     * 
     * @param   id  The id of the tool description.
     * 
     * @return  The tool Descrriptionn.
     */
    public ToolDescription getToolDescription(long id)
    {
        return toolContainer.getToolDescription(id);
    }
    
    /**
     * This method creates and adds a tool to a tool description.
     * 
     * @param   descriptionID   The id of the tool description.
     * @param   serialNumber    The serialNumber of the tool.
     */
    public void createTool(long descriptionID, long serialNumber)
    {
        toolContainer.addTool(descriptionID, new Tool(serialNumber));
    }
    
    /**
     * This method returns a tool.
     * 
     * @param   descriptionID   The id of the tool description. As a long.
     * @param   serialNumber    The serialnumber of the tool. As a long.
     * 
     * @return  The tool. As a Tool.
     */
    public Tool getTool(long descriptionID, long serialNumber)
    {
        return toolContainer.getTool(descriptionID,serialNumber);
    }
    
    /**
     * This method deletes a tool from a tool description.
     * 
     * @param   descriptionID   The id of the tool description.
     * @param   serialNumber    The serial number of the tool.
     */
    public void deleteTool(long descriptionID, long serialNumber)
    {
        toolContainer.deleteTool(descriptionID, serialNumber);
    }
    
    /**
     * This method returns a list of tool descriptions
     * 
     * @return  a list of tool descriptions.
     */
    public ArrayList<ToolDescription> getToolDescriptionList()
    {
        return toolContainer.getToolDescriptionList();
    }
}
